﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Linq.Expressions;
using Newtonsoft.Json.Linq;
using WebGrease.Css.Extensions;

using CanDoo;
using CanDoo.Core;
using CanDoo.Data;
using CanDoo.Web;
using CanDoo.FineUI;
using CanDoo.Extensions;
using CanDoo.Oil.Core.Models;
using CanDoo.Oil.Core.Contracts;
using CanDoo.Admin.Core.Contracts;
using CanDoo.Core.Data;
using FineUIPro;

namespace CanDoo.Oil.WebApp.storeOilSerialNum
{
    public partial class OnSale : ListPageBase<IOilSerialNumContract, OilSerialNum>
    {


        public IInStoreTypeContract InStoreTypeContract { get; set; }
        public IOutStoreTypeContract OutStoreTypeContract { get; set; }
        public IWarehouseContract WarehouseContract { get; set; }
        public IProductContract ProductContract { get; set; }
        public ICustomerContract CustomerContract { get; set; }
        public IOilSalesSerialNumContract OilSalesSerialNumContract { get; set; }

        #region 方法
        protected override void InitGrid()
        {
            Selector = p => new
            {
                p.InStoreType,
                p.InStoreTypeId,
                p.InStoreId,
                p.OutStoreType,
                p.OutStoreTypeId,
                p.OutStoreId,
                p.Warehouse,
                p.WarehouseId,
                p.Product,
                p.ProductId,
                p.SerialNumber,
                p.ServiceCenter,
                p.ServiceCenterId,
                p.Customer,
                p.CustomerId,
                p.OilSalesSerialNum,
                p.OilSalesSerialNumId,
                p.OilPort,
                p.UpTime,
                p.LastOil,
                p.DownTime,
                p.BirthDay,
                p.Batch,
                p.OverdueDay,
                p.Id,
                p.Name,
                p.SellBackName,
                p.OutName,
                p.BuyBackName,
                p.Status
            };
            base.InitGrid();
        }

        protected override void Search()
        {
            var key = SearchKey.GetValue();
            var oilsalesserialnumId = Web.Request.QueryString("oilsalesserialnumId").ToLong();
            var saleType = ed_SaleType.Checked;
            if(saleType)//售罄
                Filter = Filter.And(p => p.Status == OilSerialStatus.SaleOut);
            else//销售中
                Filter = Filter.And(p => p.Status == OilSerialStatus.OnSale);
            if (oilsalesserialnumId > 0L)
                Filter = Filter.And(p => p.OilSalesSerialNumId == oilsalesserialnumId);
        }
        #endregion

        #region 事件
        #region Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitGrid();
            }
        }
        #endregion

        #endregion 事件

        protected void ed_SaleType_CheckedChanged(object sender, CheckedEventArgs e)
        {
            if (ed_SaleType.Checked)
                ed_SaleType.Text = "下机油桶";
            else
                ed_SaleType.Text = "在售油桶";
            InitGrid();
        }
    }
}
